package io.wjc.log;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Pointcut;

//@Component
//@Aspect
public class LogAspect {
	private static final Log LOG = LogFactory.getLog(LogAspect.class);
	
     @Pointcut("execution(* org.springframework.data.redis.connection..*.*(..))")
     public void logPointcut(){}
     @org.aspectj.lang.annotation.Around("logPointcut()")
 
     public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{
 		long start = System.currentTimeMillis();
 		try {
 			Object result = joinPoint.proceed();
 			long end = System.currentTimeMillis();
 			LOG.info("+++++around " + joinPoint + "\tUse time : " + (end - start) + " ms!");
 			return result; 
 
 		} catch (Throwable e) {
 			long end = System.currentTimeMillis();
 			LOG.error("+++++around " + joinPoint + "\tUse time : " + (end - start) + " ms with exception : " + e.getMessage());
 			throw e;
 		}
 
     }
 
}